import java.util.Arrays;

public class Solution950 {
    public int[] deckRevealedIncreasing(int[] deck) {
        int[] ans=new int[deck.length];
        Arrays.fill(ans,-1);
        Arrays.sort(deck);
        int cur=0;
        for (int i=0;i<deck.length;i++){
            if (i!=0){
                cur=(cur+1)%deck.length;
                while (ans[cur]!=-1){
                    cur=(cur+1)%deck.length;
                }
                cur=(cur+1)%deck.length;
                while (ans[cur]!=-1){
                    cur=(cur+1)%deck.length;
                }
            }
            ans[cur]=deck[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution950().deckRevealedIncreasing(new int[]{17, 13, 11, 2, 3, 5, 7})));
    }
}
